package com.yueya.business.senior;

import java.util.Map;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.yueya.common.util.DateUtil;
import com.yueya.common.util.UUIDGenerator;

/**
 * 老人基本信息
 * @author 41654
 *
 */
@SuppressWarnings("serial")
public class SeniorBase extends Model<SeniorBase> {
	
	public static  SeniorBase dao = new SeniorBase();
	
	public boolean save(SeniorBase dao) {
		dao.set("senior_id", UUIDGenerator.getUUID());
    	dao.set("create_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}

	 
    public boolean update(SeniorBase dao) {
    	dao.set("update_time",DateUtil.getDate(DateUtil.timeFormat));
		return dao.save();
	}
    
    
    @SuppressWarnings("rawtypes")
	public Page paginate (int pageNumber,int pageSize,Map<String,String> map) {
        String select ="select sb.senior_id,sb.name,sb.avatar_url,sb.id_card,sb.birth_date,sb.phone_number,sb.food_feature,sb.self_type,sb.senior_type,sb.address   ";
        StringBuffer sql = new StringBuffer(" from jg_senior_base sb where sb.del_flag='0' ");
        
        for (Map.Entry<String, String> entry : map.entrySet()) {            
       	 if(StrKit.notBlank(entry.getValue())) {
       	   sql.append(" and sb." +entry.getKey()+ "='"+entry.getValue()+"'  ");
       	 }           
        }  
        
       if(StrKit.notBlank(map.get("order"))) {
     	     sql.append(" order by  "+map.get("order"));
       }else {
        	 sql.append(" order by sb.create_time desc,sb.update_time desc " );
       }
        
    	return dao.paginate(pageNumber, pageSize, select, sql.toString());
    }
	
    
    
}
